home *** CD-ROM | disk | FTP | other *** search
/ ftp.cs.arizona.edu / ftp.cs.arizona.edu.tar / ftp.cs.arizona.edu / icon / newsgrp / group92c.txt / 000117_icon-group-sender _Fri Dec 25 08:44:16 1992.msg < prev   
Internet Message Format  |  1993-01-04  |  11KB

  1. Received: by cheltenham.cs.arizona.edu; Sat, 26 Dec 1992 07:02:03 MST
  2. Date: 25 Dec 1992 08:44:16 -0600 (CST)
  3. From: Chris Tenaglia - 257-8765 <TENAGLIA@mis.mcw.edu>
  4. Subject: Happy Holidays
  5. To: icon-group@cs.arizona.edu
  6. Message-Id: <01GSQ5VICQ6A8WW2L6@mis.mcw.edu>
  7. Organization: Medical College of Wisconsin (Milwaukee, WI)
  8. X-Vms-To: IN%"icon-group@cs.arizona.edu"
  9. Mime-Version: 1.0
  10. Content-Type: TEXT/PLAIN; CHARSET=US-ASCII
  11. Content-Transfer-Encoding: 7BIT
  12. Status: R
  13. Errors-To: icon-group-errors@cs.arizona.edu
  14.  
  15.  
  16. Hello Colleagues!
  17.  
  18. Chris (kringle) Tenaglia is leaving a little goodie to put under your
  19. directory tree. Here is a cheap attempt at a Missile Command game.
  20. I've run it under Icon V8.7 under VMS, Unix, and V8.5 under MS-DOS.
  21.  
  22. Here are some things you'll need to know. There is a delay() procedure
  23. that keeps the game running at a steady pace. delay() is built into
  24. V8.7 on VMS and unix. Under DOS you'll need to roll your own.
  25. Funny thing is that VMS delay is 1000 per second and unix is different
  26. (maybe 100 per second). Also it does that horrible thing known as
  27. ansi escape sequences. Also to play use 7, 8, and 9 to launch a
  28. missile. 7 is leftward, 8 is straight, and 9 is right. A bug in the
  29. ultrix version (kbhit() and getch()) requires double pressing the buttons.
  30. I think q will quit the game early.
  31.  
  32. Have Fun!
  33.  
  34. Chris Tenaglia (System Manager) |  "The past explained,
  35. Medical College of Wisconsin    |   the future fortold, 
  36. 8701 W. Watertown Plank Rd.     |   the present largely appologized for."
  37. Milwaukee, WI 53226             |   Organon to The Doctor
  38. (414)257-8765                   |     
  39. tenaglia@mis.mcw.edu
  40.  
  41. #
  42. # FILE : MC.ICN
  43. # DESC : SORT OF A MISSILE COMMAND GAME
  44. #
  45. # UPDATE           BY            WHAT
  46. # 17-NOV-1992      TENAGLIA      BEGIN INITIAL WRITE
  47. #
  48. global bonus,             # bonus missile threshhold
  49.        score,             # number of missiles shot down
  50.        munitions,         # munitions supply (# of defensive missiles)
  51.        missilef,          # whether enemy missile is launched flag
  52.        missilex,          # x position of enemy missile
  53.        missiley,          # y position of enemy missile
  54.        incm,              # x increment of enemy missile
  55.        abmf,              # whether defensive missile fired flag
  56.        abmx,              # x position of defensive missile
  57.        abmy,              # y position of defensive missile
  58.        abmix              # x increment of defensive missle
  59.  
  60. procedure main()
  61.   infrastructure()        # set up defaults, globals, and munitions
  62.   banner()                # output initial banner
  63.   repeat
  64.     {
  65.     draw_base()           # initially draw base
  66.     repeat
  67.       {
  68.       enemy_launch()      # possible enemy attack
  69.       friendly_fire()     # possible defensive attack
  70.       animate()           # draw action if any
  71.       sense_status()      # sense status
  72.       delay(1000)         # pace the game
  73.       }
  74.     }
  75.   stop("\7\e[0m",at(12,24),"Game Over. \e[5mInsert another quarter.\e[0m\e[?25h\e=")
  76.   end
  77.  
  78. #
  79. # set up all the initial defaults
  80. #
  81. procedure infrastructure()
  82.   bonus    := 22
  83.   missilef := 0
  84.   missilex := 0
  85.   missiley := 0
  86.   incm     := 0
  87.   abmf     := 0
  88.   abmx     := 0
  89.   abmy     := 0
  90.   score    := 0
  91.   &random  := map(&clock,":","0")
  92.   munitions:= 10 + ?5
  93.   end
  94.  
  95. #
  96. # draw the initial environment
  97. #
  98. procedure draw_base()
  99.   write("\e[?25l\e>\e[?5l\e[0;1;33;44m\e[2J\e[H                 S.D.I. OUTPOST        [TACTICAL SITUATION DISPLAY]")
  100.   writes(at(23,1),repl("#",79))
  101.   writes(at(24,1),repl("=",79))
  102.   writes(at(24,39),"/ \\",at(23,40),"^")
  103.   writes(at(24,5)," Missiles Left : ",munitions," ")
  104.   writes(at(24,60)," Score : ",score," ")
  105.   end
  106.  
  107. #
  108. # check and occasionally launch a missile
  109. #
  110. procedure enemy_launch()
  111.   (?50 = 33) | fail
  112.   if missilef = 1 then fail
  113.   missilex := 1
  114.   missiley := 1 + ?10
  115.   missilef := 1
  116.   incm     := ?3                                                  
  117.   end
  118.  
  119. #
  120. # coordinate launch of defensive missiles
  121. #
  122. procedure friendly_fire()
  123.   kbhit() | fail
  124.   press := getch()
  125.   if abmf = 1 then
  126.     {
  127.     case press of
  128.       {
  129.       "1" | "4" | "7" | "l" | "L" : abmix := -2
  130.       "2" | "5" | "8" | "s" | "S" : abmix :=  0
  131.       "3" | "6" | "9" | "r" | "R" : abmix :=  2
  132.       "q" | "Q" | "\e"                  : stop("\e[2J\e[H")
  133.       default : writes("\7")
  134.       }
  135.     } else {
  136.     ambf :=  1
  137.     abmx := 40
  138.     abmy := 22
  139.     case press of
  140.       {
  141.       "1" | "4" | "7" | "l" | "L" : abmix := -2
  142.       "2" | "5" | "8" | "s" | "S" : abmix :=  0
  143.       "3" | "6" | "9" | "r" | "R" : abmix :=  2
  144.       "q" | "Q" | "\e": stop("\e[2J\e[H",at(12,24),"Game Over. \e[5mInsert another quarter.\e[0m\e[?25h\e=")
  145.       default : {
  146.                 writes("\7")
  147.                 fail
  148.                 }
  149.       }
  150.     if munitions <= 0 then
  151.       stop(at(12,24),"Game Over. \e[5mInsert Another Quarter!\e[0m\e=\e[?25h")
  152.     munitions -:= 1
  153.     abmf       := 1
  154.     writes(at(24,5)," Missiles Left : ",munitions," ")
  155.     }
  156.   end
  157.  
  158. #
  159. # fly the missiles
  160. #
  161. procedure animate()
  162.  
  163.   static  old_abmx,
  164.           old_abmy,
  165.           old_missilex,
  166.           old_missiley
  167.  
  168.   initial {
  169.           old_abmx     := 0
  170.           old_abmy     := 0
  171.           old_missilez := 0
  172.           old_missiley := 0
  173.           }
  174.  
  175.   #
  176.   # move the defensive missile if launched
  177.   #
  178.   if abmf = 1 then
  179.     {
  180.     writes(at(abmy,abmx),"*",at(old_abmy,old_abmx)," ")
  181.     old_abmx := abmx
  182.     old_abmy := abmy
  183.     abmx    +:= abmix
  184.     abmy    -:= 1
  185.     if abmy < 2 then
  186.       {
  187.       writes(at(old_abmy,old_abmx)," ")
  188.       abmf := 0
  189.       abmx := 0
  190.       abmy := 0
  191.       }
  192.     }
  193.  
  194.   #
  195.   # move the offensive missile if launched
  196.   #
  197.   if missilef = 1 then
  198.     {
  199.     writes(at(missiley,missilex),"   =>")
  200.     missilex +:= incm
  201.     if missilex > 76 then
  202.       {
  203.       writes(at(missiley,76),"\e[K")
  204.       missilef := 0                                 
  205.       missilex := 0
  206.       missiley := 0
  207.       incm     := 0
  208.       }
  209.     }
  210.   end
  211.  
  212. #
  213. # sense for hits and handle explosions
  214. #
  215. procedure sense_status()
  216.   static  junk
  217.   initial junk := ["=%!*@",
  218.                    "%^&(!",
  219.                    "(@^$^",
  220.                    "*)@%$",
  221.                    "@&%^(#"]
  222.   if missilef=1 & abmf=1 then
  223.     {
  224.     if abmy=missiley & (missilex < abmx < missilex+6) then
  225.       {
  226.       every 1 to 3 do
  227.         {
  228.         writes(at(abmy,abmx-4),"\e[?5h<<<<>>>>")  ; delay(2000)  # reverse screen
  229.         writes(at(abmy,abmx-4),"\e[?5l>>>><<<<")  ; delay(2000)  # normal  screen
  230.         }
  231.       every j := abmy to 22 do
  232.         {
  233.         writes(at(j,abmx-3),?junk)
  234.         delay(1000)
  235.         }
  236.       if abmx > 67 then abmx := 67   # handle edge of screen problem
  237.       writes(at(23,abmx-3),"********")              ; delay(1000)
  238.       writes(at(22,abmx-3),"\e[?5h||||||||")        ; delay(1000)
  239.       writes(at(21,abmx-5),"\e[?5l. . . . . . .")   ; delay(1000)
  240.       every j := 20 to abmy by -1 do writes(at(j,abmx-6),"\e[K")
  241.       wait(2)
  242.       score   +:= incm * (15 - missiley)
  243.       if score > bonus then
  244.         {
  245.         writes(at(12,30),"\7\e[5mBONUS MISSILE EARNED!\e[0m")
  246.         bonus     +:= 33
  247.         munitions +:= 1
  248.         delay(30000)
  249.         }
  250.       draw_base()
  251.       abmf     := 0
  252.       abmx     := 0
  253.       abmy     := 0
  254.       missilef := 0
  255.       missilex := 0
  256.       missiley := 0
  257.       }
  258.     }
  259.   end
  260.                     
  261. #
  262. # output initial banner for this game
  263. #             
  264. procedure banner()
  265.   write("\e[0;1;33;44m\e[2J\e[H                                                                 ")
  266.   write("                                                                 ")
  267.   write("###############################################################################")
  268.   write("                                                                 ")
  269.   write("             ***   *   *  *****  ****    ***    ****  *****      ")
  270.   write("           *   *  *   *    *    *   *  *   *  *        *         ")
  271.   write("          *   *  *   *    *    ****   *   *   ***     *          ")
  272.   write("         *   *  *   *    *    *      *   *      *    *           ")
  273.   write("         ***    ***     *    *       ***   ****     *            ")
  274.   write("                                                                 ")
  275.   write("                ****          ****          ***                  ")
  276.   write("              *              *   *          *                    ")
  277.   write("              ****          *   *          *                     ")
  278.   write("                 *         *   *          *                      ")
  279.   write("            ****   **     ****   **     ***  **                  ")
  280.   write("                                                                 ")
  281.   write("                                                                 ")
  282.   write("###############################################################################")
  283.   wait(3)
  284.   end
  285.  
  286. #
  287. # move cursor to specified screen position
  288. #
  289. procedure at(row,column)
  290.   return "\e[" || row || ";" || column || "f"
  291.   end
  292.  
  293. #
  294. # procedure to wait n seconds
  295. #
  296. procedure wait(n)
  297.   delay(n * 10000)
  298.   return
  299. ##  secs := &clock[-2:0] + n
  300. ##  if secs > 58 then secs -:= 60
  301. ##  repeat
  302. ##    {
  303. ##    now := &clock[-2:0]
  304. ##    if now > secs then break
  305. ##    }
  306. ##  return
  307.   end
  308.  
  309. ##################################################################
  310. #                                                                #
  311. # THIS PROCEDURE PULLS ALL THE ELEMENTS (TOKENS) OUT OF A LINE   #
  312. # BUFFER AND RETURNS THEM IN A LIST. A VARIABLE NAMED 'CHARS'    #
  313. # CAN BE STATICALLY DEFINED HERE OR GLOBAL. IT IS A CSET THAT    #
  314. # CONTAINS THE VALID CHARACTERS THAT CAN COMPOSE THE ELEMENTS    #
  315. # ONE WISHES TO EXTRACT.                                         #
  316. #                                                                #
  317. ##################################################################
  318. procedure parse(line,delims)
  319.   static chars
  320.   chars  := &cset -- delims
  321.   tokens := []
  322.   line ? while tab(upto(chars)) do put(tokens,tab(many(chars)))
  323.   return tokens
  324.   end
  325.  
  326. ##################################################################
  327. #                                                                #
  328. # THIS PROCEDURE IS TERRIBLY HANDY IN PROMPTING AND GETTING      #
  329. # AN INPUT STRING                                                #
  330. #                                                                #
  331. ##################################################################
  332. procedure input(prompt)
  333.   writes(prompt)
  334.   return read()
  335.   end
  336.  
  337.